package com.cskaoyan.market.controller;

import com.cskaoyan.market.service.AdminDashBoardService;
import com.cskaoyan.market.service.AdminDashBoardServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/8 17:16
 */
@WebServlet("/admin/dashboard")
public class AdminDashBoardController extends HttpServlet {
    private AdminDashBoardService adminDashBoardService=new AdminDashBoardServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        totalCount(req,resp);
    }

    private void totalCount(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Map<String,Integer> items=adminDashBoardService.count();
        Object o= ResponseUtil.okMap(items);
        resp.getWriter().println(JacksonUtil.getObjectMapper().writeValueAsString(o));


    }
}
